<extend name="Base/common"/>
<block name="css">

</block>
<block name="body">
    <header class="mui-bar mui-bar-nav dl_header">
        <a href="javascript:history.back();" id="close" class="iconfont icon-guanbi dl_closed"></a>
        <a href="{:U('Agent/sudentManage')}" class="dl_fast">信息管理</a>
    </header>
    <div class="mui-content" id="container_wrap">
        <div  style="display: -webkit-box;-webkit-box-orient: horizontal;-webkit-box-pack: center;overflow: hidden;">
            <img src="__PUBLIC__/Home/images/index/xglogo.png" class="img-responsive center-block logo"/>
        </div>
        <form class="form-horizontal dl_form" id="form_one">
            <input type="hidden" value="{$data['id']}" name="id">
            <div class="form-group form-line-input" style="margin-top:10px;">
                <input type="text" class="form-control" value="{$data.name}" id="name"  name="name">
                <label for="name" <notempty name="data['name']">style="top: 0;font-size: 1.3rem;"</notempty>>姓名</label>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" value="{$data.ID_number}" id="ID_number"  name="ID_number">
                <label for="ID_number" <notempty name="data['ID_number']">style="top: 0;font-size: 1.3rem;"</notempty>>身份证</label>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" value="{$data.home_address}" id="home_address" name="home_address">
                <label for="home_address" <notempty name="data['home_address']">style="top: 0;font-size: 1.3rem;"</notempty>>家庭住址</label>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" value="{$data.school}" id="school"  name="school">
                <label for="school"  <notempty name="data['school']">style="top: 0;font-size: 1.3rem;"</notempty>>毕业学校</label>
            </div>
            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <select id="major" class="form-control edited" name="major">
                    <volist name="major" id="vo">
                        <option value="{$vo.id}" <if condition="$data['major'] eq $vo['id']">selected</if>>{$vo.title}</option>
                    </volist>
                </select>
                <label for="major">专业</label>
            </div>

            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" value="{$data.introducer}" id="introducer"  name="introducer">
                <label for="introducer" <notempty name="data['introducer']">style="top: 0;font-size: 1.3rem;"</notempty>>介绍人</label>
            </div>

            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="text" class="form-control" value="{$data.introducer_phone}" id="introducer_phone"  name="introducer_phone">
                <label for="introducer_phone" <notempty name="data['introducer_phone']">style="top: 0;font-size: 1.3rem;"</notempty>>介绍人电话</label>
            </div>

            <div class="form-group form-line-input has-success" style="margin-top:10px;">
                <input type="file" accept="image/*" class="myfile" id="img" name="img" style="display: none;">
                <label for="img" class="btn btn-success">缴费凭证</label>
            </div>

            <div class="form-group form-line-input has-success">
                <input type="hidden" value="" id="pay_evidence" name="pay_evidence">
                <img id="pay_evidence_img" style="max-width: 230px;max-height: 110px;" src="" >
            </div>

            <a href="javascript:" id="add_btn" class="btn btn-mini btn-primary common_btn">提交</a>

        </form>

    </div>


</block>

<block name="script">
    <script>
        $('.myfile').change(function(event) {
            // 根据这个 <input> 获取文件的 HTML5 js 对象
            var files = event.target.files,file = files[0];;
            // 获取目前上传的文件
            var imgarr = ['image/png','image/jpg','image/jpeg','image/gif'];//图片格式
            // 实例化一个表单数据对象
            var formData = new FormData();
            if(file.size > 1024 * 1024 * 2) {
                $.dialog({
                    content : '图片大小不能超过 2MB!',
                    title: "alert",
                    time : 1000
                });
                $('.myfile').val('');
                return false;
            }
            //区分文件类型  inArray()函数
            if($.inArray (file.type,imgarr) != -1){
                formData.append('download',file);
            }else {
                $.dialog({
                    content : '只能上传图片',
                    title: "alert",
                    time : 1000
                });
                $('.myfile').val('');
                return false;
            }
            $.ajax({
                url: "{:U('Home/File/upload')}",
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    //提示上传失败的原因
                    if(result.status==1)
                    {
                        $.dialog({
                            content : "上传成功",
                            title: "ok",
                            time : 1000
                        });
                        $("#pay_evidence").val(result.url);
                        $("#pay_evidence_img").attr('src',result.url);
                        return false;
                    }else{
                        $.dialog({
                            content : "上传失败",
                            title: "alert",
                            time : 1000
                        });
                    }
                },
                error: function (result) {
                    $.dialog({
                        content : "上传失败",
                        title: "alert",
                        time : 1000
                    });
                }
            });
        });

        $("#add_btn").click(function(){
            var submit = true;
            var  $name=$("input[name=name]").val(),
                 $ID_number=$("input[name=ID_number]").val(),
                 $introducer=$("input[name=introducer]").val(),
                 $introducer_phone=$("input[name=introducer_phone]").val(),
                 $id=$("input[name=id]").val();

            if($name==''){
                $.dialog({
                    content : '请填写学生名字',
                    title: "alert",
                    time : 1000
                });
                return false;
            }

            if($ID_number==''){
                $.dialog({
                    content : '请填写身份证号',
                    title: "alert",
                    time : 1000
                });
                return false;
            }

            if($introducer==''){
                $.dialog({
                    content : '请填写介绍人名字',
                    title: "alert",
                    time : 1000
                });
                return false;
            }

            if($introducer_phone==''){
                $.dialog({
                    content : '请填写介绍人电话',
                    title: "alert",
                    time : 1000
                });
                return false;
            }


            if($ID_number!=''){
                var reg = /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
                if(reg.test($ID_number)){
                    if($id==''){
                        $.post('{:U("Agent/checkfield")}', {ID_number:$ID_number,type:2}, function(data){
                            if(data.status){
                                $.dialog({
                                    content : data.info,
                                    title: "alert",
                                    time : 1000
                                });
                            }else{
                                save_action();
                            }
                        });
                    }else{
                        save_action();
                    }
                }else{
                    $.dialog({
                        content : '身份证号格式不正确',
                        title: "alert",
                        time : 1000
                    });
                    return false;
                }

            }

        });

        function save_action(){
            $.post('{:U("Agent/saveSudentInfo")}', $("form").serialize(), function(data){
                if(data.status){
                    $.dialog({
                        content : data.info,
                        title: "ok",
                        time : 1000
                    });
                    setTimeout(function () {
                        location.reload();
                    },1000);
                }else{
                    $.dialog({
                        content : data.info,
                        title: "alert",
                        time : 1000
                    });
                }
            });
        }
    </script>
</block>